{% extends "base.html" %}

{% block content %}
<div class="row">
    <div class="col-md-12 mb-4">
        <div class="jumbotron bg-light p-5 rounded">
            <h1 class="display-4">欢迎来到课题组技能与知识中心</h1>
            <p class="lead">这是一个用于展示课题组成员技能和分享知识的平台。</p>
            {% if not current_user.is_authenticated %}
            <hr class="my-4">
            <p>请登录以访问更多功能。</p>
            <a class="btn btn-primary btn-lg" href="{{ url_for('auth.login') }}" role="button">登录</a>
            {% endif %}
        </div>
    </div>
</div>

{% if current_user.is_authenticated %}
<div class="row">
    <div class="col-md-8">
        <div class="card mb-4">
            <div class="card-header bg-primary text-white">
                <h5 class="mb-0">最新知识文章</h5>
            </div>
            <div class="card-body">
                {% if recent_articles %}
                <div class="list-group">
                    {% for article in recent_articles %}
                    <a href="{{ url_for('articles.view', id=article.id) }}" class="list-group-item list-group-item-action">
                        <div class="d-flex w-100 justify-content-between">
                            <h5 class="mb-1">{{ article.title }}</h5>
                            <small>{{ article.created_at.strftime('%Y-%m-%d') }}</small>
                        </div>
                        <p class="mb-1">作者: {{ article.author.name }}</p>
                        <small>
                            {% for skill in article.skills %}
                            <span class="badge bg-secondary">{{ skill.name }}</span>
                            {% endfor %}
                        </small>
                    </a>
                    {% endfor %}
                </div>
                {% else %}
                <p class="text-muted">暂无文章</p>
                {% endif %}
                <div class="mt-3">
                    <a href="{{ url_for('articles.index') }}" class="btn btn-outline-primary">查看所有文章</a>
                    <a href="{{ url_for('articles.create') }}" class="btn btn-primary">创建新文章</a>
                </div>
            </div>
        </div>
    </div>
    
    <div class="col-md-4">
        <div class="card mb-4">
            <div class="card-header bg-primary text-white">
                <h5 class="mb-0">技能标签</h5>
            </div>
            <div class="card-body">
                {% if skills %}
                <div class="d-flex flex-wrap gap-2">
                    {% for skill in skills %}
                    <a href="{{ url_for('articles.by_skill', skill_id=skill.id) }}" class="badge bg-secondary text-decoration-none">{{ skill.name }}</a>
                    {% endfor %}
                </div>
                {% else %}
                <p class="text-muted">暂无技能标签</p>
                {% endif %}
                <div class="mt-3">
                    <a href="{{ url_for('skills.index') }}" class="btn btn-outline-primary">查看所有技能</a>
                    {% if current_user.is_admin() %}
                    <a href="{{ url_for('skills.create') }}" class="btn btn-primary">添加技能标签</a>
                    {% endif %}
                </div>
            </div>
        </div>
        
        <div class="card">
            <div class="card-header bg-primary text-white">
                <h5 class="mb-0">快速链接</h5>
            </div>
            <div class="card-body">
                <div class="list-group">
                    <a href="{{ url_for('users.index') }}" class="list-group-item list-group-item-action">成员列表</a>
                    <a href="{{ url_for('users.profile', id=current_user.id) }}" class="list-group-item list-group-item-action">我的个人档案</a>
                    <a href="{{ url_for('users.edit_profile') }}" class="list-group-item list-group-item-action">编辑我的档案</a>
                    {% if current_user.is_admin() %}
                    <a href="{{ url_for('admin.index') }}" class="list-group-item list-group-item-action">管理面板</a>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
</div>
{% endif %}
{% endblock %}